package cn.glenn.egweibo1.controller;

import cn.glenn.egweibo1.base.response.JsonResult;
import cn.glenn.egweibo1.mapper.UserMapper;
import cn.glenn.egweibo1.pojo.dto.UserAddParam;
import cn.glenn.egweibo1.pojo.enity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/v1/user/")
@Slf4j
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @PostMapping("add")
    public JsonResult addUser(@RequestBody UserAddParam param){
        log.debug("param信息"+param);
        User user = new User();
        BeanUtils.copyProperties(param, user);
        user.setCreateTime(new Date());
        log.debug("user信息"+user);
        int num = userMapper.insertUser(user);
        if(num>0){return JsonResult.success(user);}
        else return JsonResult.fail();
    }
}
